package com.example.demo.controller;

import com.example.demo.pojo.Administrator;
import com.example.demo.service.AdministratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author yanglup
 * @create 2020-12-05 19:11
 */
@Controller
public class BackAdministratorController {
    @Autowired
    AdministratorService administratorService;

    /**查询管理员列表*/
    @RequestMapping("/Administratorlist")
    public String Administratorlist(Model model) {
        List<Administrator> administratorlist = administratorService.Administratorlist();
        model.addAttribute("administratorlists",administratorlist);
        Integer allnumber=administratorService.Administratorlistnumber();
        model.addAttribute("allnumber",allnumber);
        return "Administratorlist";
    }

    /**管理员列表1--跳转到add*/
    @RequestMapping("/Administratoradd")
    public String Administratoradd(Model model){
        return "Administratoradd";
    }
    /**管理员列表2--保存数据跳回list*/
    @PostMapping("/Administratoraddtijiao")//post
    public String Administratoraddtijiao(Model model,Administrator administrator){
        String username=administrator.getUsername();
        String password=administrator.getPassword();
        String email=administrator.getEmail();
        administratorService.Administratoraddtijiao(username,password,email);
        return "redirect:/Administratorlist";
    }


    /**跳转到修改页面*/
    @RequestMapping("/Administratorupdate")
    public String Administratorupdate(Model model, Integer adminid, HttpSession session){
        //通过id查询
        Administrator administrator=administratorService.Administratorupdate(adminid);
        model.addAttribute("administrator",administrator);
        session.setAttribute("adminid",adminid);
        return "Administratorupdate";
    }
    /**订单提交2--保存数据跳回list*/
    @PostMapping("/Administratorupdatetijiao")//post
    public String Administratorupdatetijiao(Model model, Administrator administrator,HttpSession session){
        Integer adminid1= (Integer) session.getAttribute("adminid");//点击传入的adminid
        Integer adminid2=administrator.getAdminid();
        String username=administrator.getUsername();
        String password=administrator.getPassword();
        String email=administrator.getEmail();
        administratorService.Administratorupdatetijiao(adminid1,adminid2,username,password,email);
        return "redirect:/Administratorlist";
    }

    /**删除轮播图*/
    @RequestMapping("/Administratdelete")
    public String Administratdelete(Integer adminid){
        administratorService.Administratdelete(adminid);
        return "redirect:/Administratorlist";
    }


}
